package com.efast.cafe.portal.controller.common;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.portal.service.base.IBaseCityService;
import com.efast.cafe.portal.service.base.IBaseCountryService;
import com.efast.cafe.portal.service.base.IBaseDistrictService;
import com.efast.cafe.portal.service.base.IBaseProvinceService;

@Controller
public class CommonAreaController {
		@Autowired
		private IBaseCityService baseCityService;
		@Autowired
		private IBaseProvinceService baseProvinceService;
		@Autowired
		private  IBaseCountryService baseCountryService;
		@Autowired
		private  IBaseDistrictService  baseDistrictService;

		
		@RequestMapping(value = "/frame_center/common/querycitybyprovince")
		public @ResponseBody ResultBean queryAllCityByProvince(
				@RequestBody Map<String,Integer> map){
			
			 ResultBean result=new ResultBean(true,"'");
			 if(map.containsKey("provinceId")){
				Integer provinceId=map.get("provinceId");
				result.setObject(baseCityService.queryAllCityByProvince(provinceId.toString()));
			} 
			 return result;
		}
		
		@RequestMapping(value = "/frame_center/common/queryallcountry")
		public @ResponseBody ResultBean queryAllCountry(){
			ResultBean result=new ResultBean(true,"'");
			 result.setObject(baseCountryService.queryAllCountry());
			 return result;
		}
		
		@RequestMapping(value = "/frame_center/common/querydistrictbycity")
		public @ResponseBody ResultBean  queryAllDistrictByCity(
				@RequestBody Map<String,Integer> map){
			ResultBean result=new ResultBean(true,"'");
			if(map.containsKey("cityId")){
			 Integer cityId=map.get("cityId");
			 result.setObject(baseDistrictService.queryAllDistrictByCity(cityId.toString()));
			}
			 return result;
		}
		@RequestMapping(value = "/frame_center/common/queryprovincebycountry")
		public @ResponseBody ResultBean  queryAllProvinceByCountry(@RequestBody Map<String,Integer> map){
			ResultBean result=new ResultBean(true,"'");
			Integer countryId = null;
			if(map.containsKey("countryId")){
				 countryId=map.get("countryId");
			}
			if(countryId!=null){
				 result.setObject(baseProvinceService.queryAllProvinceByCountry(countryId.toString()));
			}else{
				 result.setObject(baseProvinceService.queryAllProvinceByCountry(null));
			}
			return result;
		}
		
		@RequestMapping(value = "/frame_center/common/queryProCityDis")
		public @ResponseBody ResultBean  queryProCityDis(@RequestBody Map<String,Integer> map){
			ResultBean result=new ResultBean(true,"");
			result.setObject(baseProvinceService.queryProCityDis());
			return result;
		}
	
	
}
